package org.noote.libs.camera.surface;

import java.io.IOException;

import org.noote.libs.camera.CameraInterface;

import android.annotation.TargetApi;
import android.graphics.SurfaceTexture;
import android.os.Build;
import android.util.Log;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class CameraSurface extends CameraInterface {
	private static final String TAG = "CameraSurface";
	private static final int MAGIC_TEXTURE_ID = 0x10;

	protected SurfaceTexture _texture = null;
	
	public CameraSurface() {
		super();
	}
	
	@Override
	public boolean open(int cameraId)
	{
		boolean bRet = false;
		
		// The Surface has been created, acquire the camera and tell it where
		// to draw.
		if(!super.open(cameraId))
		{
			Log.e(TAG, "Cannot open camera");
			return false;
		}
		_texture = new SurfaceTexture(MAGIC_TEXTURE_ID);
		try {
			getCamera().setPreviewTexture(_texture);
			bRet = setParameters();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			bRet = false;
		}

		return bRet;
	}	
}
